package com.wxzz.elearing.course.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.service.IService;
import com.wxzz.elearing.course.dto.*;
import com.wxzz.elearing.course.entity.*;
import com.wxzz.elearing.course.vo.*;
import com.wxzz.elearning.common.dto.FeignEnterpriseDto;
import com.wxzz.elearning.common.dto.FeignStudyTimeDto;
import com.wxzz.elearning.common.dto.FeignWxUserDto;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * <p>
 * 课程 服务类
 * </p>
 *
 * @author
 * @since 2021-03-10
 */
public interface ICurriculumService extends IService<Curriculum> {

    /**
     * 课程列表(后台/小程序)
     *
     * @param type          0-后台 1-小程序
     * @param curriculumDto
     * @param isApply       是否为审核申请的课程 0-否 1-是  如讲师申请上架课程 企业申请到平台课程
     * @return
     */
    ReturnVO<JgPageVo<List<Curriculum>>> listCurriculumByCategory(HttpServletResponse response, Integer type, CurriculumDto curriculumDto, Integer isApply);

    /**
     * 培训计划列表(小程序)
     *
     * @param enterpriseId
     * @return
     */
    ReturnVO listCurriculumByCategory4train(Long enterpriseId, Long wxUserId, CurriculumByCategory4trainDto curriculumByCategory4trainDto);

    /**
     * 查询课程详情(后台)
     *
     * @param curriculumId
     */
    ReturnVO<CurriculumVo> selectCurriculumDetail(Long enterpriseId, Long curriculumId);

    /**
     * 查询课程详情(小程序)
     *
     * @param curriculumId 课程id
     * @return
     */
    ReturnVO<Curriculum> wxSelectCurriculumDetail(Long enterpriseId, Long wxUserId, Long curriculumId);

    /**
     * 查询课程章节列表(后台/小程序)
     *
     * @param curriculumId 课程id
     * @return
     */
    ReturnVO<List<CurriculumUnit>> listCurriculumSection(Long wxUserId, Long curriculumId);

    // ReturnVO updateWxUserCurriculum();

    /**
     * 查询课程章节测评/查询在线考试测评(后台/小程序)
     *
     * @param curriculumSectionId
     * @return
     */
    ReturnVO<List<CurriculumSectionTopic>> listCurriculumSectionTopic(Long curriculumSectionId, Integer topicCategory);

    /**
     * 添加课程
     *
     * @param curriculum
     * @return
     */
    ReturnVO saveCurriculum(Long adminUserId, Curriculum curriculum);

    /**
     * 修改课程
     *
     * @param curriculum
     * @return
     */
    ReturnVO updateCurriculum(Curriculum curriculum);

    /**
     * 解禁/禁用课程
     *
     * @param curriculum
     * @return
     */
    ReturnVO isBanCurriculum(Curriculum curriculum);

    /**
     * 删除课程
     *
     * @param curriculumId
     * @return
     */
    ReturnVO deleteCurriculum(Long curriculumId);

    /**
     * 上架课程
     *
     * @param curriculumId
     * @param isDocent     是否为讲师 0-否 1-是
     * @return
     */
    ReturnVO updateStatus(Long curriculumId, Integer isDocent);

    /**
     * 下架课程
     *
     * @param curriculumId
     * @return
     */
    ReturnVO updateStatusDown(Long curriculumId);

    /**
     * 企业上架课程到平台
     *
     * @return
     */
    ReturnVO updatePlatformStatus(UpdatePlatformStatusDto updatePlatformStatusDto);

    /**
     * 添加或修改课程章节
     *
     * @param curriculumSection
     * @return
     */
    ReturnVO saveCurriculumSection(CurriculumSection curriculumSection);

    /**
     * 根据章节id查询详情
     *
     * @return
     */
    ReturnVO<CurriculumSection> selectCurriculumSectionDetail(Long curriculumSectionId);

    /**
     * 新增章节时根据课程id展示单元
     *
     * @param curriculumId
     * @return
     */
    ReturnVO<List<CurriculumUnit>> listCurriculumUnit(Long curriculumId);

    /**
     * 新增课程单元
     *
     * @param curriculumUnit
     * @return
     */
    ReturnVO saveCurriculumUnit(List<CurriculumUnit> curriculumUnit);

    /**
     * 根据id删除课程单元
     *
     * @param curriculumUnitId
     * @return
     */
    ReturnVO deleteCurriculumUnitById(Long curriculumUnitId);

    /**
     * 根据讲师id列出课程
     *
     * @return
     */
    ReturnVO<JgPageVo<List<Curriculum>>> listCurriculumByDocentId(CurriculumByDocentDto curriculumByDocentDto);

    /**
     * 企业购买平台课程
     *
     * @param curriculumId
     * @return
     */
    ReturnVO enterpriseBuyCurriculum(JSONObject jsonObject, Long curriculumId);

    /**
     * 将课程同步给购买的企业
     *
     * @param enterpriseId
     * @param curriculumId
     */
    void copyNewCurriculum(Long enterpriseId, Long curriculumId, Long orderId);

    /**
     * 审核课程
     *
     * @param checkCurriculumDto
     * @return
     */
    ReturnVO checkCurriculum(CheckCurriculumDto checkCurriculumDto);

    /**
     * 审核修改课程日志
     *
     * @param curriculumCheckLogDto
     * @return
     */
    ReturnVO<JgPageVo<List<CurriculumCheckLog>>> listCurriculumCheckLogByDocentId(CurriculumCheckLogDto curriculumCheckLogDto);

    /**
     * 根据微信用户id查询学习课程数据(远程调用)
     *
     * @param wxUserId
     * @return
     */
    ReturnVO<String> selectWxUserCurriculumDataByWxUserId(Long wxUserId);

    /**
     * 根据订单id查询企业购买的课程信息(远程调用)
     *
     * @param orderId
     * @return
     */
    ReturnVO<JSONObject> selectCurriculum4EnterpriseByOrderId(Long orderId);

    BigDecimal getStudySchedule(Long wxUserId, Long curriculumId);

    /**
     * 根据课程id查询人员学习情况(后台)
     *
     * @return
     */
    ReturnVO<JgPageVo<List<WxUserCurriculum>>> selectWxUserByCurriculum(WxUserByCurriculumDto wxUserByCurriculumDto);

    /**
     * 根据课程id查询企业的学习情况
     *
     * @param wxUserByCurriculumDto
     * @return
     */
    ReturnVO<JgPageVo<List<FeignEnterpriseDto>>> selectEnterpriseByCurriculum(WxUserByCurriculumDto wxUserByCurriculumDto);

    /**
     * 根据课程id查询人员学习情况数据统计(后台)
     *
     * @param curriculumId
     * @return
     */
    ReturnVO<WxUserCurriculumStatisticsVo> selectWxUserCurriculumStatisticsVoByCurriculum(Long curriculumId);

    /**
     * 根据课程id查询企业学习情况数据统计(后台)
     *
     * @param curriculumId
     * @return
     */
    ReturnVO<WxUserCurriculumStatisticsVo> selectEnterpriseCurriculumStatisticsVoByCurriculum(Long curriculumId);

    /**
     * 查询企业学习情况详情(后台)
     *
     * @param curriculumId
     * @return
     */
    ReturnVO<EnterpriseCurriculumVo> selectEnterpriseCurriculumVoByCurriculum(Long enterpriseId, Long curriculumId);

    /**
     * 查询课程的学习情况
     *
     * @param curriculumId
     * @return
     */
    ReturnVO<EnterpriseCurriculumVo> selectCurriculumVoByCurriculum(Long curriculumId);

    /**
     * 查询个人学习情况详情(后台)
     *
     * @param wxUserId
     * @param curriculumId
     * @return
     */
    ReturnVO<WxUserCurriculumVo> selectWxUserCurriculumVoByWxUserId(Long wxUserId, Long curriculumId);

    /**
     * 查询企业的学习时长
     *
     * @param enterpriseId
     * @return
     */
    ReturnVO<StudyTimeVo> selectStudyTimeVoByEnterpriseId(Long enterpriseId);

    /**
     * 查询企业的学习时长(远程调用)
     *
     * @param enterpriseId
     * @return
     */
    FeignStudyTimeDto selectFeignStudyTimeDto(Long enterpriseId);

    /**
     * 查询该企业的课程英雄榜
     *
     * @param feignWxUserDtoByCurriculumDto
     * @return
     */
    ReturnVO<JgPageVo<List<FeignWxUserDto>>> selectFeignWxUserDtoByCurriculum(HttpServletResponse response,Long enterpriseId, FeignWxUserDtoByCurriculumDto feignWxUserDtoByCurriculumDto);

    /**
     * 查询个人中心数据
     *
     * @param wxUserId
     * @return
     */
    ReturnVO<WxUserCenterVo> selectWxUserCenterVo(Long wxUserId);

    /**
     * 查询该企业明星讲师英雄榜
     *
     * @param enterpriseId
     * @param feignWxUserDtoByCurriculumDto
     * @return
     */
    ReturnVO<JgPageVo<List<FeignWxUserDto>>> selectFeignWxUserDtoByDocent(HttpServletResponse response,Long enterpriseId, FeignWxUserDtoByCurriculumDto feignWxUserDtoByCurriculumDto);

    /**
     * 查询该企业明星讲师英雄榜
     *
     * @param enterpriseId
     * @param feignWxUserDtoByCurriculumDto
     * @return
     */
    List<FeignWxUserDto> selectDocentCurriculumStatisticsVo(Long enterpriseId, FeignWxUserDtoByCurriculumDto feignWxUserDtoByCurriculumDto);

    /**
     * 查询课程总数(远程调用)
     *
     * @return
     */
    Integer countByCourse();

    /**
     * 平台学习人数（概况总览）
     *
     * @return
     */
    ReturnVO<CountStudyStatisticsVo> countStudyPersonNum();

    /**
     * 当前企业的学习数据(概况总览)
     *
     * @param enterpriseId
     * @return
     */
    ReturnVO<CountStudyEnterpriseStatisticsVo> selectCountStudyEnterpriseStatisticsVo(Long enterpriseId);


    /**
     * 查询企业的课程数量
     *
     * @param enterpriseId
     * @return
     */
    Integer selectCountByEnterpriseId(Long enterpriseId);

    /**
     * 职员用户的每日学习时长
     *
     * @return
     */
    ReturnVO<CountStudyWxUserStatisticsVo> selectCountStudyWxUserStatisticsVo(SelectCountStudyWxUserStatisticsDto selectCountStudyWxUserStatisticsDto);

    /**
     * 章节测评题导入
     *
     * @param token
     * @param curriculumSectionId
     * @param file
     * @return
     */
    ReturnVO importTopicSection(String token, Long curriculumSectionId, MultipartFile file);

    /**
     * 导出一个章节的测评题
     *
     * @param curriculumSectionId
     * @return
     */
    void exportTopicSection(HttpServletResponse response, Long curriculumSectionId);

    /**
     * 同步课程数据
     * @param curriculumId
     */
    void courseUpdate(Long curriculumId);

    /**
     * 判断当前企业或平台是否有课程分类和讲师
     * (0-可以添加课程 1-请添加分类 2-请添加讲师)
     * @param enterpriseId
     * @return
     */
    ReturnVO isHaveCategoryAndDocent(Long enterpriseId);
}
